
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.1 Requests的简单使用 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="深入了解Requests.html" />
    
    
    <link rel="prev" href="Python爬虫学习目标.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="正则表达式.html">
            
                <a href="正则表达式.html">
            
                    
                    第一章：正则表达式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="正则表达式入门.html">
            
                <a href="正则表达式入门.html">
            
                    
                    1.1 正则表达式入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="Python中的正则表达式.html">
            
                <a href="Python中的正则表达式.html">
            
                    
                    1.2 Python中的正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="基本正则表达式.html">
            
                <a href="基本正则表达式.html">
            
                    
                    1.3 基本正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="分组.html">
            
                <a href="分组.html">
            
                    
                    1.4 分组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="先行断言.html">
            
                <a href="先行断言.html">
            
                    
                    1.5 先行断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="标记.html">
            
                <a href="标记.html">
            
                    
                    1.6 标记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="替换与正则表达式编译.html">
            
                <a href="替换与正则表达式编译.html">
            
                    
                    1.7 替换与正则编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="正则表达式练习.html">
            
                <a href="正则表达式练习.html">
            
                    
                    1.8 正则表达式练习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Python爬虫学习目标.html">
            
                <a href="Python爬虫学习目标.html">
            
                    
                    第二章：爬虫与Requests
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="Requests的简单使用.html">
            
                <a href="Requests的简单使用.html">
            
                    
                    2.1 Requests的简单使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="深入了解Requests.html">
            
                <a href="深入了解Requests.html">
            
                    
                    2.2 深入了解Requets
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="结构化与非结构化.html">
            
                <a href="结构化与非结构化.html">
            
                    
                    第三章：非结构化与结构化数据提取
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="正则抓取.html">
            
                <a href="正则抓取.html">
            
                    
                    3.1 使用正则的爬虫
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="xpath与XML.html">
            
                <a href="xpath与XML.html">
            
                    
                    3.2 Xpath与XML类库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="lxml.html">
            
                <a href="lxml.html">
            
                    
                    3.3 LXML库的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="Xpath爬虫案例.html">
            
                <a href="Xpath爬虫案例.html">
            
                    
                    3.4 案例：贴吧图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="Json与JsonPath.html">
            
                <a href="Json与JsonPath.html">
            
                    
                    3.5 Json与Json数据获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="实例：糗事百科网站抓取.html">
            
                <a href="实例：糗事百科网站抓取.html">
            
                    
                    3.6 糗事百科网站爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >2.1 Requests的简单使用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="requests&#x7684;&#x7B80;&#x5355;&#x4F7F;&#x7528;">Requests&#x7684;&#x7B80;&#x5355;&#x4F7F;&#x7528;</h1>
<p>Requests&#x7684;&#x6587;&#x6863;&#x975E;&#x5E38;&#x5B8C;&#x5907;&#xFF0C;&#x4E2D;&#x6587;&#x6587;&#x6863;&#x4E5F;&#x76F8;&#x5F53;&#x4E0D;&#x9519;&#x3002;Requests&#x80FD;&#x5B8C;&#x5168;&#x6EE1;&#x8DB3;&#x5F53;&#x524D;&#x7F51;&#x7EDC;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x652F;&#x6301;Python 2.6--3.7&#x3002;</p>
<p>&#x5F00;&#x6E90;&#x5730;&#x5740;&#xFF1A;<a href="https://github.com/kennethreitz/requests" target="_blank">https://github.com/kennethreitz/requests</a></p>
<p>&#x4E2D;&#x6587;&#x6587;&#x6863; API&#xFF1A; <a href="http://docs.python-requests.org/zh_CN/latest/index.html" target="_blank">http://docs.python-requests.org/zh_CN/latest/index.html</a></p>
<h2 id="1&#x57FA;&#x672C;get&#x8BF7;&#x6C42;&#xFF1A;">1.&#x57FA;&#x672C;GET&#x8BF7;&#x6C42;&#xFF1A;</h2>
<pre><code class="lang-python">response = requests.get(<span class="hljs-string">&quot;http://www.baidu.com/&quot;</span>)
<span class="hljs-comment"># &#x4E5F;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x5199;</span>
<span class="hljs-comment"># response = requests.request(&quot;get&quot;, &quot;http://www.baidu.com/&quot;)</span>
</code></pre>
<h2 id="2&#x6DFB;&#x52A0;-headers-&#x548C;-&#x67E5;&#x8BE2;&#x53C2;&#x6570;">2.&#x6DFB;&#x52A0; headers &#x548C; &#x67E5;&#x8BE2;&#x53C2;&#x6570;</h2>
<p>&#x5982;&#x679C;&#x60F3;&#x6DFB;&#x52A0; <code>headers</code>&#xFF0C;&#x53EF;&#x4EE5;&#x4F20;&#x5165;<code>headers</code>&#x53C2;&#x6570;&#x6765;&#x589E;&#x52A0;&#x8BF7;&#x6C42;&#x5934;&#x4E2D;&#x7684;<code>headers</code>&#x4FE1;&#x606F;&#x3002;&#x5982;&#x679C;&#x8981;&#x5C06;&#x53C2;&#x6570;&#x653E;&#x5728;<code>url</code>&#x4E2D;&#x4F20;&#x9012;&#xFF0C;&#x53EF;&#x4EE5;&#x5229;&#x7528;<code>params</code> &#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests

kw = {<span class="hljs-string">&apos;wd&apos;</span>:<span class="hljs-string">&apos;&#x957F;&#x57CE;&apos;</span>}

headers = {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36&quot;</span>}

<span class="hljs-comment"># params &#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#x6216;&#x8005;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x8BE2;&#x53C2;&#x6570;&#xFF0C;&#x5B57;&#x5178;&#x7C7B;&#x578B;&#x81EA;&#x52A8;&#x8F6C;&#x6362;&#x4E3A;url&#x7F16;&#x7801;&#xFF0C;&#x4E0D;&#x9700;&#x8981;urlencode()</span>
response = requests.get(<span class="hljs-string">&quot;http://www.baidu.com/s?&quot;</span>, params = kw, headers = headers)

<span class="hljs-comment"># &#x67E5;&#x770B;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#xFF0C;response.text &#x8FD4;&#x56DE;&#x7684;&#x662F;Unicode&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;</span>
<span class="hljs-comment">#print (response.text)</span>

<span class="hljs-comment"># &#x67E5;&#x770B;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#xFF0C;response.content&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x8282;&#x6D41;&#x6570;&#x636E;</span>
<span class="hljs-comment">#print (response.content)</span>

<span class="hljs-comment"># &#x67E5;&#x770B;&#x5B8C;&#x6574;url&#x5730;&#x5740;</span>
<span class="hljs-keyword">print</span> (response.url)

<span class="hljs-comment"># &#x67E5;&#x770B;&#x54CD;&#x5E94;&#x5934;&#x90E8;&#x5B57;&#x7B26;&#x7F16;&#x7801;</span>
<span class="hljs-keyword">print</span> (response.encoding)

<span class="hljs-comment"># &#x67E5;&#x770B;&#x54CD;&#x5E94;&#x7801;</span>
<span class="hljs-keyword">print</span> (response.status_code)
</code></pre>
<h2 id="&#x5C0F;demo">&#x5C0F;Demo</h2>
<h3 id="&#x901A;&#x8FC7;requests&#x83B7;&#x53D6;&#x65B0;&#x6D6A;&#x9996;&#x9875;">&#x901A;&#x8FC7;<code>requests</code>&#x83B7;&#x53D6;&#x65B0;&#x6D6A;&#x9996;&#x9875;</h3>
<pre><code class="lang-python"><span class="hljs-comment">#coding=utf-8</span>
<span class="hljs-keyword">import</span>  requests
response = requests.get(<span class="hljs-string">&quot;http://www.sina.com&quot;</span>)
print(response.request.headers)
print(response.content.decode())
</code></pre>
<pre><code class="lang-html">{&apos;User-Agent&apos;: &apos;python-requests/2.21.0&apos;, &apos;Accept-Encoding&apos;: &apos;gzip, deflate&apos;, &apos;Accept&apos;: &apos;*/*&apos;, &apos;Connection&apos;: &apos;keep-alive&apos;}
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-comment">&lt;!-- [ published at 2019-04-28 21:33:00 ] --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;Content-type&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;text/html; charset=utf-8&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;X-UA-Compatible&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;IE=edge&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>&#x65B0;&#x6D6A;&#x9996;&#x9875;<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;keywords&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;&#x65B0;&#x6D6A;,&#x65B0;&#x6D6A;&#x7F51;,SINA,sina,sina.com.cn,&#x65B0;&#x6D6A;&#x9996;&#x9875;,&#x95E8;&#x6237;,&#x8D44;&#x8BAF;&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;description&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;&#x65B0;&#x6D6A;&#x7F51;&#x4E3A;&#x5168;&#x7403;&#x7528;&#x6237;24&#x5C0F;&#x65F6;&#x63D0;&#x4F9B;&#x5168;&#x9762;&#x53CA;&#x65F6;&#x7684;&#x4E2D;&#x6587;&#x8D44;&#x8BAF;&#xFF0C;&#x5185;&#x5BB9;&#x8986;&#x76D6;&#x56FD;&#x5185;&#x5916;&#x7A81;&#x53D1;&#x65B0;&#x95FB;&#x4E8B;&#x4EF6;&#x3001;&#x4F53;&#x575B;&#x8D5B;&#x4E8B;&#x3001;&#x5A31;&#x4E50;&#x65F6;&#x5C1A;&#x3001;&#x4EA7;&#x4E1A;&#x8D44;&#x8BAF;&#x3001;&#x5B9E;&#x7528;&#x4FE1;&#x606F;&#x7B49;&#xFF0C;&#x8BBE;&#x6709;&#x65B0;&#x95FB;&#x3001;&#x4F53;&#x80B2;&#x3001;&#x5A31;&#x4E50;&#x3001;&#x8D22;&#x7ECF;&#x3001;&#x79D1;&#x6280;&#x3001;&#x623F;&#x4EA7;&#x3001;&#x6C7D;&#x8F66;&#x7B49;30&#x591A;&#x4E2A;&#x5185;&#x5BB9;&#x9891;&#x9053;&#xFF0C;&#x540C;&#x65F6;&#x5F00;&#x8BBE;&#x535A;&#x5BA2;&#x3001;&#x89C6;&#x9891;&#x3001;&#x8BBA;&#x575B;&#x7B49;&#x81EA;&#x7531;&#x4E92;&#x52A8;&#x4EA4;&#x6D41;&#x7A7A;&#x95F4;&#x3002;&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;always&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;referrer&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;mask-icon&quot;</span> <span class="hljs-attr">sizes</span>=<span class="hljs-string">&quot;any&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;//www.sina.com.cn/favicon.svg&quot;</span> <span class="hljs-attr">color</span>=<span class="hljs-string">&quot;red&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;stencil&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;PGLS000022&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;publishid&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;30,131,1&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;verify-v1&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;6HtwmypggdgP1NLw7NOuQBI2TW8+CfkYCoyeB8IDbn8=&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;360-site-verification&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;63349a2167ca11f4b9bd9a8d48354541&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;application-name&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;&#x65B0;&#x6D6A;&#x9996;&#x9875;&quot;</span>/&gt;</span>
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment">#coding=utf-8</span>
<span class="hljs-keyword">import</span>  requests
response = requests.get(<span class="hljs-string">&quot;http://www.sina.com&quot;</span>)
print(response.request.headers)
print(response.text)
</code></pre>
<pre><code class="lang-html">{&apos;User-Agent&apos;: &apos;python-requests/2.21.0&apos;, &apos;Accept-Encoding&apos;: &apos;gzip, deflate&apos;, &apos;Accept&apos;: &apos;*/*&apos;, &apos;Connection&apos;: &apos;keep-alive&apos;}
<span class="hljs-meta">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span class="hljs-comment">&lt;!-- [ published at 2019-04-28 21:31:03 ] --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;Content-Type&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;text/html; charset=utf-8&quot;</span> /&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>WWW.SINA.COM<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;keywords&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;sina, &#xE6;&#x96;&#xB0;&#xE6;&#xB5;&#xAA;&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;description&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;&#xE6;&#x96;&#xB0;&#xE6;&#xB5;&#xAA;&#xE9;&#xA6;&#x96;&#xE9;&#xA1;&#xB5;&quot;</span> /&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/css&quot;</span>&gt;</span><span class="undefined">
</span></code></pre>
<h4 id="&#x4EA7;&#x751F;&#x4E0A;&#x8FF0;&#x95EE;&#x9898;&#x7684;&#x539F;&#x56E0;">&#x4EA7;&#x751F;&#x4E0A;&#x8FF0;&#x95EE;&#x9898;&#x7684;&#x539F;&#x56E0;</h4>
<ol>
<li><code>requests</code>&#x9ED8;&#x8BA4;&#x81EA;&#x5E26;&#x7684;<code>Accept-Encoding</code>&#x5BFC;&#x81F4;&#x6216;&#x8005;&#x65B0;&#x6D6A;&#x9ED8;&#x8BA4;&#x53D1;&#x9001;&#x7684;&#x5C31;&#x662F;&#x538B;&#x7F29;&#x4E4B;&#x540E;&#x7684;&#x7F51;&#x9875;</li>
<li>&#x4F46;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;<code>content.read()</code>&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x56E0;&#x4E3A;<code>requests</code>&#xFF0C;&#x81EA;&#x5E26;&#x89E3;&#x538B;&#x538B;&#x7F29;&#x7F51;&#x9875;&#x7684;&#x529F;&#x80FD;</li>
<li>&#x5F53;&#x6536;&#x5230;&#x4E00;&#x4E2A;&#x54CD;&#x5E94;&#x65F6;&#xFF0C;<code>Requests</code> &#x4F1A;&#x731C;&#x6D4B;&#x54CD;&#x5E94;&#x7684;&#x7F16;&#x7801;&#x65B9;&#x5F0F;&#xFF0C;&#x7528;&#x4E8E;&#x5728;&#x4F60;&#x8C03;&#x7528;response.text &#x65B9;&#x6CD5;&#x65F6;&#x5BF9;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x89E3;&#x7801;&#x3002;<code>Requests</code> &#x9996;&#x5148;&#x5728; <code>HTTP</code> &#x5934;&#x90E8;&#x68C0;&#x6D4B;&#x662F;&#x5426;&#x5B58;<code>4</code>. &#x5728;&#x6307;&#x5B9A;&#x7684;&#x7F16;&#x7801;&#x65B9;&#x5F0F;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x4F1A;&#x4F7F;&#x7528; chardet.detect&#x6765;&#x5C1D;&#x8BD5;&#x731C;&#x6D4B;&#x7F16;&#x7801;&#x65B9;&#x5F0F;&#xFF08;&#x5B58;&#x5728;&#x8BEF;&#x5DEE;&#xFF09;</li>
<li>&#x66F4;&#x63A8;&#x8350;&#x4F7F;&#x7528;<code>response.content.deocde()</code></li>
</ol>
<h2 id="&#x7EC3;&#x4E60;">&#x7EC3;&#x4E60;</h2>
<p>&#x4F7F;&#x7528;requests&#x722C;&#x53D6;&#x4EFB;&#x610F;&#x8F93;&#x5165;&#x7684;&#x767E;&#x5EA6;&#x8D34;&#x5427;&#x7684;&#x7F51;&#x9875;&#xFF0C;&#x5E76;&#x4FDD;&#x5B58;&#x5230;&#x672C;&#x5730;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Python爬虫学习目标.html" class="navigation navigation-prev " aria-label="Previous page: 第二章：爬虫与Requests">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="深入了解Requests.html" class="navigation navigation-next " aria-label="Next page: 2.2 深入了解Requets">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.1 Requests的简单使用","level":"1.3.1","depth":2,"next":{"title":"2.2 深入了解Requets","level":"1.3.2","depth":2,"path":"notes/深入了解Requests.md","ref":"notes/深入了解Requests.md","articles":[]},"previous":{"title":"第二章：爬虫与Requests","level":"1.3","depth":1,"path":"notes/Python爬虫学习目标.md","ref":"notes/Python爬虫学习目标.md","articles":[{"title":"2.1 Requests的简单使用","level":"1.3.1","depth":2,"path":"notes/Requests的简单使用.md","ref":"notes/Requests的简单使用.md","articles":[]},{"title":"2.2 深入了解Requets","level":"1.3.2","depth":2,"path":"notes/深入了解Requests.md","ref":"notes/深入了解Requests.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"notes/Requests的简单使用.md","mtime":"2019-05-04T08:39:48.019Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-08T02:50:45.307Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

